<template lang="pug">
.page
  .EmployeeBook
    .search-form.mb-15.pl-10.pr-10(v-if="hasFind")
      Form.ivu-row(ref="formInvoice" :model="formInvoice" :label-width="120")
        FormItem.form-item.ivu-col.pr-20.mb-15(v-for="(item, index) of formItem" :label="item.label" :key="index" :class="item.style" :prop="item.prop")
          template(v-if="item.type === 'select'")
            Select(v-if="item.prop === 'HRName' || item.model === 'SalaryBank'" v-model="formInvoice[item.model]" :placeholder="item.placeholder" clearable filterable)
              Option(
                v-for="(c_item, index) in arrListDown[item.options]"
                :value="c_item.label"
                :key="index"
              ) {{ c_item.label }}
            Select(v-else v-model="formInvoice[item.model]" :placeholder="item.placeholder" clearable filterable)
              Option(
                v-for="(c_item, index) in arrListDown[item.options]"
                :value="c_item.value"
                :key="index"
              ) {{ c_item.label }}
          template(v-if="item.type === 'input'")
            Input(v-model="formInvoice[item.model]" :type="item.inputType" :placeholder="item.placeholder" clearable)
          template(v-if="item.type === 'input-number'")
            div.d-f-c
              Input(v-model="formInvoice[item.model]" :type="item.inputType" :placeholder="item.placeholder" clearable)
              span.ml-15 天
          template(v-if="item.type === 'button'")
            Button(type="info" @click="searchFn") 查询

    .pl-20.pr-20.bg-white
      Table.hasTitle-table.beautiful-table(:columns="thead" :data="tableData" :stripe="true" ref="demoTable"
        @on-selection-change="handleOnSelectChange"
      )
        .clearfix.overflow-hidden(slot="header")
          Icon.pull-left.cursor-pointer.font-36.text-gray-ccc.line-h-70.mr-10(type="ios-add-circle-outline")
          .table-title-lefttxt.pull-left
            |合计
            span.text-info.pl-5.pr-5.font-weight {{tableComone.totalRows}}
            |条
            Divider(type="vertical")
            |在职
            span.text-info.pl-5.pr-5.font-weight {{tableComone.inServiceCount}}
            |人
            Divider(type="vertical")
            |离职
            span.text-error.pl-5.pr-5.font-weight {{tableComone.outServiceCount}}
            |人

          Dropdown.pull-right.pt-15.has-button-dropdown(placement="bottom-end")
            a(href="javascript:void(0)")
              Icon.text-info.font-24(type="md-more")
            DropdownMenu(slot="list")
              DropdownItem(v-if="hasBatchUpdateEmployees")
                Button(type="text" @click="handleShowBatchModifyModal") 批量修改花名册
              DropdownItem(v-if="hasCreate")
                Button(type="text" @click="handleShowChooseCompanyModal('')") 新增
              DropdownItem(v-if="hasEmployeeDimission" :disabled="!selectedEmployeeArr.length > 0")
                Button(type="text" @click="employeeDimission" :disabled="!selectedEmployeeArr.length > 0") 离职
              //- DropdownItem(v-if="hasPostEmployeeTransfer" :disabled="!selectedEmployeeArr.length > 0")
              //-   Button(type="text" @click="checkEmployeeTransfer" :disabled="!selectedEmployeeArr.length > 0") 调动
              DropdownItem(v-if="hasExport")
                Button(type="text" @click="exportEmployees") 导出

          .pull-right.clearfix
            .clearfix.table-title-btns
              //- Button.mr-10(v-if="hasImportEmployees" type="info" @click="handleShowBatchImportContractModal") 批量导入合同
              Button.mr-10(v-if="hasImportEmployees" type="info" @click="handleShowBatchImportModal") 批量导入花名册
              //- Button.mr-10(v-if="hasBatchUpdateEmployees" type="info" @click="handleShowBatchModifyModal") 批量修改花名册
              Button.mr-10(v-if="hasImportInsured" type="info" @click="handleShowBatchImportBaseDataModal") 批量导入基数
              .display-inline-block.mr-10
                Dropdown(v-if="hasChangesAdd" trigger="click" placement="bottom-start" @on-click="handleChangeAddDifferent('addDifferent', $event)")
                  Button(type="info" :disabled="!selectedEmployeeArr.length > 0")
                    span.pr-5 异动新增
                    Icon(type="ios-arrow-down")
                  DropdownMenu(slot="list")
                    DropdownItem(v-for="(item,index) in arrListDown.securitytype" :name="item.value" :key="index") {{item.label}}新增
              .display-inline-block.mr-10
                Dropdown(v-if="hasChangesReduce" trigger="click" placement="bottom-start" @on-click="handleChangeAddDifferent2('redDifferent', $event)")
                  Button(type="info" :disabled="!selectedEmployeeArr.length > 0")
                    span.pr-5 异动减少
                    Icon(type="ios-arrow-down")
                  DropdownMenu(slot="list")
                    DropdownItem(v-for="(item,index) in arrListDown.securitytype" :name="item.value" :key="index") {{item.label}}减少

        template(slot-scope="{ row, index }" slot="action")
          Button.mr-10(type="text" size="small" @click="goEmployeeCreate(row.id, row.companyId, row.companyName, row.typeValue, true)") 详情
          Button.mr-10(v-if="hasGetConfig" type="text" size="small" @click="CheckEmployeeSet(row)") 参保信息修改
          //- Button.mr-10(v-if="hasUpload" type="text" size="small" @click="handleShowUploadAccessoryModal(row.id)") 附件上传
          //- Button.mr-10(v-if="hasDelete" type="text" size="small" @click="isDeleteModal(row.id)") 删除

        .clearfix.pl-20.pr-20(slot="footer")
          Page(
            :current="tableComone.pageIndex"
            :total="tableComone.totalRows"
            @on-change="onChangePage"
            @on-page-size-change="onpageSizeChange"
            show-sizer
            show-total
            placement="top"
            prev-text="上一页"
            next-text="下一页"
            :page-size-opts="[10, 20, 30, 50, 100]"
          )

    //- 异动改变弹窗
    ChangeDifferentModal(ref="ChangeDifferentModal" :changeDifferentTitleId="changeDifferentTitleId" :changeDifferentTitleStr="changeDifferentTitleStr" :changeDifferentAction="changeDifferentAction" :selectedEmployeeArr="selectedEmployeeArr" @query="searchFn")
    //- 异动减少弹窗
    ChangeDifferentModalNew(ref="ChangeDifferentModalNew" :changeDifferentTitleId="changeDifferentTitleId" :changeDifferentTitleStr="changeDifferentTitleStr" :changeDifferentAction="changeDifferentAction" :selectedEmployeeArr="selectedEmployeeArr" @query="searchFn")
    //- 批量导入花名册弹窗
    BatchImportModal(ref="BatchImportModal" @handleMaxSizeTen="handleMaxSizeTen" @query="searchFn")
    //- 批量导入基数弹窗
    BatchImportBaseDataModal(ref="BatchImportBaseDataModal" @handleMaxSizeTen="handleMaxSizeTen" @query="searchFn")
    //- 批量导入合同弹窗
    BatchImportContractModal(ref="BatchImportContractModal" @handleMaxSizeTen="handleMaxSizeTen" @query="searchFn")
    //- 批量上传照片附件弹窗
    //- BatchUploadImgModal(ref="BatchUploadImgModal" @before="handleBeforeUploadPhoto" @uploadZip="handleUploadPhotoSuccess")
    BatchUploadImgModal(ref="BatchUploadImgModal" @handleMaxSizeTifty="handleMaxSizeTifty")
    //- 批量修改花名册弹窗
    BatchModifyModal(ref="BatchModifyModal" @handleMaxSizeTen="handleMaxSizeTen" @query="searchFn")
    //- 商保替换弹窗
    ShangbaoReplaceModal(ref="ShangbaoReplaceModal" :selectedEmployeeArr="selectedEmployeeArr" @query="searchFn")
    //- 附件上传弹窗
    UploadAccessoryModal(ref="UploadAccessoryModal" @handleMaxSizeTen="handleMaxSizeTen")
    //- 公积金在职调基弹窗
    //- GongjijinZZtiaojiModal(ref="GongjijinZZtiaojiModal")
    //- 公积金补缴调基弹窗
    GongjijinBJtiaojiModal(ref="GongjijinBJtiaojiModal")
    //- 删除员工
    DeleteEmployeeModal(ref="DeleteEmployeeModal" @ok="handleSureDelete" :modalTitle="deleteEmployeeTitle")
    //- 是否下载错误模板
    ErrorTemplateModal(ref="ErrorTemplateModal")
    //- 选择公司
    ChooseCompanyModal(ref="ChooseCompanyModal" @goEmployeeCreate="ChooseCompanyOk")
    //- 调动弹窗
    MobilizeModal(ref="MobilizeModal" @query="query")
</template>

<script>
// import {mapActions, mapGetters} from 'vuex'
// import {EMPLOYEE_BOOK_LIST} from '@/store/module/employee/types'

import dataApi from '@/api/data.js'
import { EmployeesApi } from '@/api/Employees.api.js'
import { SysWelfarePercentEmployeeConfigApi } from '@/api/SysWelfarePercentEmployeeConfig.api.js'
import { SysWelfarePercentEmployeeAdjustConfigApi } from '@/api/SysWelfarePercentEmployeeAdjustConfig.api.js'
import { SysAreaApi } from '@/api/SysArea.api.js'
import { Common } from '@/utils/common.js'

import { EmployeeBookListThead } from './RtableHead.js'
import { rosterListThead } from './RtableHead.js'
// import { EmployeeBookListThead } from '../../../business-sector/customerManage/EmployeeBook/EBtableHead.js'
import _cloneDeep from 'clone-deep'
import ChangeDifferentModal from '../../../business-sector/customerManage/EmployeeBook/modal/changeDifferentModal.vue'
import ChangeDifferentModalNew from '../../../business-sector/customerManage/EmployeeBook/modal/changeDifferentModalNew.vue'
import BatchImportModal from '../../../business-sector/customerManage/EmployeeBook/modal/batchImportModal.vue'
import BatchImportBaseDataModal from '../../../business-sector/customerManage/EmployeeBook/modal/batchImportBaseDataModal.vue'
import BatchImportContractModal from '../../../business-sector/customerManage/EmployeeBook/modal/batchImportContractModal.vue'
import BatchUploadImgModal from '../../../business-sector/customerManage/EmployeeBook/modal/batchUploadImgModal.vue'
import BatchModifyModal from '../../../business-sector/customerManage/EmployeeBook/modal/batchModifyModal.vue'
import ShangbaoReplaceModal from '../../../business-sector/customerManage/EmployeeBook/modal/shangbaoReplaceModal.vue'
import UploadAccessoryModal from '../../../business-sector/customerManage/EmployeeBook/modal/uploadAccessoryModal.vue'
import GongjijinZZtiaojiModal from '../../../business-sector/customerManage/EmployeeBook/modal/gongjijinZZtiaojiModal.vue'
import GongjijinBJtiaojiModal from '../../../business-sector/customerManage/EmployeeBook/modal/gongjijinBJtiaojiModal.vue'
import DeleteEmployeeModal from '../../../business-sector/customerManage/EmployeeBook/modal/deleteEmployeeModal.vue'
import ErrorTemplateModal from '@/components/errorTemplateModal.vue'
import ChooseCompanyModal from './modal/chooseCompanyModal.vue'
import MobilizeModal from './modal/mobilizeModal.vue'
import config from '@/config'
const baseUrl = process.env.NODE_ENV === 'development' ? config.baseUrl.dev : config.baseUrl.pro.replace('/api', '/')

export default {
  name: 'roster',

  components: {
    ChangeDifferentModal,
    ChangeDifferentModalNew,
    BatchImportModal,
    BatchImportBaseDataModal,
    BatchImportContractModal,
    BatchUploadImgModal,
    BatchModifyModal,
    ShangbaoReplaceModal,
    UploadAccessoryModal,
    GongjijinZZtiaojiModal,
    GongjijinBJtiaojiModal,
    DeleteEmployeeModal,
    ErrorTemplateModal,
    ChooseCompanyModal,
    MobilizeModal
  },

  data () {
    return {
      loading: false,
      IsDueRadio: 0,
      IsRetireRadio: 0,

      companyId: '', // 公司ID
      companyName: '', // 公司名称
      employeeId: '', // 员工ID
      thead: _cloneDeep(EmployeeBookListThead),
      tableData: [],
      radioModel: '',
      formInvoice: {
        Name: '',
        IdCardNo: '',
        BeHiring: '',
        CompanyName: '',
        ParentName: '',
        HRName: '',
        IsDue: '',
        IsRetire: '',
        SalaryBank: ''
      },
      formItem: [
        { type: 'input', label: '姓名：', placeholder: '请输入姓名', prop: 'Name', model: 'Name', inputType:"text", style: 'ivu-col-span-8' },
        { type: 'input', label: '身份证号码：', placeholder: '请输入身份证号码', prop: 'IdCardNo', model: 'IdCardNo', inputType:"text", style: 'ivu-col-span-8' },
        { type: 'select', label: '在职状态：', placeholder: '请选择在职状态', prop: 'BeHiring', model: 'BeHiring', style: 'ivu-col-span-8', options: 'isBeHiring' },
        { type: 'select', label: '工资发放银行：', placeholder: '请选择工资发放银行', prop: 'SalaryBank', model: 'SalaryBank', style: 'ivu-col-span-8', options: 'bankList' },
        // { type: 'input', label: '公司名称：', placeholder: '请输入公司名称', prop: 'CompanyName', model: 'CompanyName', inputType:"text", style: 'ivu-col-span-8' },
        // { type: 'input', label: '上级公司：', placeholder: '请输入上级公司', prop: 'ParentName', model: 'ParentName', inputType:"text", style: 'ivu-col-span-8' },
        // { type: 'select', label: '所属客服：', placeholder: '请选择所属客服', prop: 'HRName', model: 'HRName', style: 'ivu-col-span-8', options: 'server' },
        // { type: 'input-number', label: '合同到期：', placeholder: '请输入', prop: 'IsDue', model: 'IsDue', inputType:"number", style: 'ivu-col-span-8' },
        // { type: 'input-number', label: '退休：', placeholder: '请输入', prop: 'IsRetire', model: 'IsRetire', inputType:"number", style: 'ivu-col-span-8' },
        { type: 'button', style: 'ivu-col-span-8' }
      ],
      rules: {
        IdCardNo: [
          { type: 'string', message: '请输入正确的身份证号码', pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/ }
        ]
      },
      addDifferentArr: [
        { id: 0, text: '社保新增' },
        { id: 1, text: '公积金新增' },
        { id: 2, text: '商保新增' },
        { id: 3, text: '社保公积金新增' },
        { id: 4, text: '社保商保新增' },
        { id: 5, text: '社保公积金商保新增' },
        { id: 6, text: '公积金商保新增' }
      ],
      redDifferentArr: [
        { id: 0, text: '社保减少' },
        { id: 1, text: '公积金减少' },
        { id: 2, text: '商保减少' },
        { id: 3, text: '社保公积金减少' },
        { id: 4, text: '社保商保减少' },
        { id: 5, text: '社保公积金商保减少' },
        { id: 6, text: '公积金商保减少' }
      ],
      changeDifferentAction: '', // 所点击的异动操作是新增or减少
      changeDifferentTitleId: '', // 传给modal的title(异动下拉选项的字段id)
      changeDifferentTitleStr: '', // 传给modal的title(异动下拉选项的字段内容)
      selectedEmployeeId: [], // 勾选的id集合,array格式
      selectedEmployeeArr: [], // 勾选的id, name数组集合
      // totalcount: 10, // 总条目
      // pageIndex: 1, // 翻页索引
      // pageSize: 30, // 每页的数目
      tableComone: {
        pageIndex: 1, // 页码
        totalRows: 0, // 总条数
        pageSize: 10, // 当前页面展示条数
        inServiceCount: 0, // 在职
        outServiceCount: 0 // 离职
      },
      downloadUrl: '',
      arrListDown: {
        isBeHiring: [{ label: '在职', value: 1 }, { label: '离职', value: 0 }, { label: '离职未报停', value: -1 }],
        securitytype: [],
        server: [],
        bankList: []
      },
      deleteEmployeeTitle: '是否确认删除该员工？',
      errorTemplateTitle: '你上传的文件数据有误，是否需要下载错误数据模板查看详情？',
      // importExcel: {
      //   uploadLoading: false,
      //   progressPercent: 0,
      //   showProgress: false,
      //   showRemoveFile: false,
      //   file: null
      // }
      batchImportFile: null,
      batchModifyFile: null
    }
  },

  watch: {
    $route (to, from) {
      console.log(from,'$route')
      if (from.name === 'home') {
        this.initPage()
      }
    }
  },

  computed: {
    actionArr () {
      let arr = this.$store.state.user.actionAccess.map(item => {
        return item.code
      })
      return arr
    },
    // 导出
    hasExport () {
      return this.actionArr.indexOf('ExportEmployees') > -1
    },
    // 查询
    hasFind () {
      return this.actionArr.indexOf('Find') > -1
    },
    // 离职信息填写
    hasEmployee_PostResignInfo () {
      return this.actionArr.indexOf('Employee_PostResignInfo') > -1
    },
    // 调动
    hasPostEmployeeTransfer () {
      return this.actionArr.indexOf('PostEmployeeTransfer') > -1
    },
    // 商保替换
    hasEmpCommercialChange () {
      return this.actionArr.indexOf('EmpCommercialChange') > -1
    },
    // 公积金调基
    hasProvidentFundAdjustConfig () {
      return this.actionArr.indexOf('ProvidentFundAdjustConfig') > -1
    },
    // 异动新增
    hasChangesAdd () {
      return this.actionArr.indexOf('ChangesAdd') > -1
    },
    // 批量上传照片附件
    hasBatchPictureUpload () {
      return this.actionArr.indexOf('BatchPictureUpload') > -1
    },
    // 批量修改
    hasBatchUpdateEmployees () {
      return this.actionArr.indexOf('BatchUpdateEmployees') > -1
    },
    // 离职
    hasEmployeeDimission () {
      return this.actionArr.indexOf('EmployeeDimission') > -1
    },
    // 异动减少
    hasChangesReduce () {
      return this.actionArr.indexOf('ChangesReduce') > -1
    },
    // 删除
    hasDelete () {
      return this.actionArr.indexOf('Delete') > -1
    },
    // 附件上传
    hasUpload () {
      return this.actionArr.indexOf('Upload') > -1
    },
    // 新增
    hasCreate () {
      return this.actionArr.indexOf('Create') > -1
    },
    // 参保信息修改
    hasGetConfig () {
      return this.actionArr.indexOf('GetConfig') > -1
    },
    // 批量导入
    hasImportEmployees () {
      return this.actionArr.indexOf('ImportEmployees') > -1
    },
    // 批量导入基数
    hasImportInsured () {
      return this.actionArr.indexOf('ImportInsured') > -1
    },
    // 参保信息设置
    hasGetBatchConfig () {
      return this.actionArr.indexOf('GetBatchConfig') > -1
    },
    // 编辑
    hasEdit () {
      return this.actionArr.indexOf('Edit') > -1
    }
  },

  mounted () {
    this.companyId = this.$route.query.companyId
    this.companyName = this.$route.query.companyName
    console.log('从客户信息点击过来时所带的公司ID为：' + this.companyId + ', 公司名称：' + this.companyName)
    this.getEnum()
    this.servers()
    this.getBankList()
    this.initPage()

    // 清除历史点击过的员工基本信息
    localStorage.removeItem('employeeBasicInfo')
  },

  methods: {
    // ...mapActions({
    //   storeQueryEmployeeBookList: EMPLOYEE_BOOK_LIST
    // }),
    // 初始化页面
    initPage () {
      console.log('⭐ this.$route.params: ', this.$route.params)
      var params = this.$route.params

      if (params.type === 0 || params.type === 1 || params.type === -1) {
        this.formInvoice.BeHiring = params.type
        this.formInvoice.IsDue = ''
        this.formInvoice.IsRetire = ''
      } else if (params.isDue) {
        this.formInvoice.BeHiring = 1
        this.formInvoice.IsDue = '60'
        this.formInvoice.IsRetire = ''
      } else if (params.IsRetire) {
        this.formInvoice.BeHiring = 1
        this.formInvoice.IsDue = ''
        this.formInvoice.IsRetire = '180'
      } else {
        this.formInvoice.BeHiring = ''
        this.formInvoice.IsDue = ''
        this.formInvoice.IsRetire = ''
      }
      // this.filtrate.areaName = params.areaName // 城市名称
      // this.filtrate.flag = params.flag
      this.query()
    },

    // 数据字典
    getEnum () {
      let groupName = 'change.securitytype'
      Common.getEnum(groupName, this.arrListDown)
      // console.log('数据字典：', this.arrListDown)
    },

    // 获取客服
    async servers () {
      var params = {
        PageIndex: 1,
        PageSize: 100,
        Args: ''
      }
      Common.servers(params, this.arrListDown, 'server')
    },

    // 获取银行下拉
    async getBankList () {
      Common.getBankList({}, this.arrListDown, 'bankList')
    },

    // 搜索
    searchFn () {
      this.tableComone.pageIndex = 1
      this.query()
    },

    /**
     * 分页页码变动
     * @param {Number} val pageIndex
     */
    onChangePage (val) {
      this.tableComone.pageIndex = val
      this.query()
    },
    /**
     * 分页页码变动
     * @param {Number} val pageSize
     */
    onpageSizeChange (val) {
      this.tableComone.pageIndex = 1
      this.tableComone.pageSize = val
      this.query()
    },
    /**
     * 分页查询接口
     * @param {Object} obj {pageIndex, pageSize}
     */
    async query () {
      var params = {
        IsDue: this.formInvoice.IsDue,
        IsRetire: this.formInvoice.IsRetire,
        BeHiring: this.formInvoice.BeHiring,
        Name: this.formInvoice.Name,
        IdCardNo: this.formInvoice.IdCardNo,
        CompanyName: this.formInvoice.CompanyName,
        HRName: this.formInvoice.HRName,
        ParentName: this.formInvoice.ParentName,
        // CompanyID: this.companyId, // 花名册总列表，没有单条的companyId
        HasPaging: true,
        PageIndex: this.tableComone.pageIndex,
        PageSize: this.tableComone.pageSize,
        OrderBy: '',
        Asc: true,
        SalaryBank: this.formInvoice.SalaryBank,
      }

      let res = await EmployeesApi.getEmployeeListNew(params)
      if (res.data.code === 200 && res.data.success) {
        this.tableData = res.data.data
        this.tableComone.totalRows = res.data.totalRows // 总条数
        this.tableComone.inServiceCount = res.data.inServiceCount // 在职数
        this.tableComone.outServiceCount = res.data.outServiceCount // 离职数
      } else {
        this.tableData = []
      }
      this.selectedEmployeeId = []
      this.selectedEmployeeArr = []
    },

    // 去往参保信息设置页面(单条)
    goInsuranceInfoSet (row, checkEmployeeNum) {
      this.$router.push({
        path: '/InsuranceInfoSet',
        name: 'InsuranceInfoSet',
        query: {
          companyId: row.companyId,
          companyName: row.companyName,
          employeeId: row.id,
          checkEmployeeNum: checkEmployeeNum,
          isFromRoster: true
        }
      })
    },

    // 去往参保信息设置页面(单条)前验证是否属于同一公司
    async CheckEmployeeSet (row) {
      var params = {
        employeeId: row.id
      }
      let res = await SysWelfarePercentEmployeeConfigApi.CheckEmployeeSet(params)
      if (res.status === 200 && res.data.success) {
        console.log('去往参保信息设置页面(单条)前验证是否属于同一公司，所返回的data是: ' + res.data.data)
        var checkEmployeeNum = res.data.data
        this.goInsuranceInfoSet(row, checkEmployeeNum)
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 去往参保信息设置页面(批量)前验证是否属于同一公司
    async checkEmployeeBatch () {
      var params = {
        EmployeeIdList: this.selectedEmployeeId
      }
      let res = await SysWelfarePercentEmployeeConfigApi.checkEmployee(params)
      if (res.status === 200 && res.data.success) {
        console.log('去往参保信息设置页面(批量)前验证是否属于同一公司，所返回的data是: ' + res.data.data)
        var checkEmployeeNum = res.data.data
        this.goInsuranceInfoBatchSet(checkEmployeeNum)
        localStorage.setItem('isDataOperator', JSON.stringify(res.data.isDataOperator))
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 去往参保信息设置页面(批量)
    goInsuranceInfoBatchSet (checkEmployeeNum) {
      // localStorage.setItem('selectedEmployeeId', JSON.stringify(this.selectedEmployeeId))
      this.$router.push({
        path: '/InsuranceInfoBatchSet',
        name: 'InsuranceInfoBatchSet',
        query: {
          companyId: this.companyId,
          companyName: this.companyName,
          checkEmployeeNum: checkEmployeeNum,
          isBatch: true,
          isBatchOut: false,
        }
      })
    },

    // 新增员工前选择公司
    handleShowChooseCompanyModal () {
      this.$refs.ChooseCompanyModal.show()
    },

    // 已经选择好了公司
    ChooseCompanyOk (companyObj) {
      this.getSingle(companyObj)
      // this.goEmployeeCreate('', companyObj.value, companyObj.label, '', false)
    },

    // 选择公司后获取公司详情
    getSingle (companyObj) {
      dataApi.getSingle({id: companyObj.value}).then(res => {
        if (res.status === 200 && res.data.success) {
          var currentCustomerManage = {
            companyId: res.data.data.id,
            typeValue: res.data.data.type
          }
          localStorage.setItem('currentCustomerManage', JSON.stringify(currentCustomerManage))
          this.goEmployeeCreate('', companyObj.value, companyObj.label, res.data.data.type, false)
        } else {
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },

    // 去往员工新增/详情页面
    goEmployeeCreate (employeeId, companyId, companyName, typeValue, isOnlyView) {
      var currentCustomerManage = {
        companyId: companyId,
        typeValue: typeValue
      }
      console.log('🐶🐶🐶 ', currentCustomerManage)
      localStorage.setItem('currentCustomerManage', JSON.stringify(currentCustomerManage))
      console.log('去往员工新增/详情页面时，员工ID是：' + employeeId + '，公司ID是：' + companyId + '，公司名称是：' + companyName + '，公司类型是：' + typeValue)
      if (employeeId !== '') {
        this.$router.push({
          path: '/EmployeeCreate',
          name: 'EmployeeCreate',
          query: {
            companyId: companyId,
            companyName: companyName,
            employeeId: employeeId,
            isOnlyView: isOnlyView,
            isFromRoster: true
          }
        })
      } else {
        this.$router.push({
          path: '/EmployeeCreate',
          name: 'EmployeeCreate',
          query: {
            companyId: companyId,
            companyName: companyName,
            isCreateNew: true,
            isFromRoster: true
          }
        })
      }
    },

    // 表格选择操作
    handleOnSelectChange (value) {
      this.selectedEmployeeArr = value.map((item) => {
        return { id: item.id, name: item.name, companyId: item.companyId }
      })
      this.selectedEmployeeId = value.map((item) => {
        return item.id
      })
      console.log('列表勾选数组1', this.selectedEmployeeArr)
      console.log('列表勾选数组2', this.selectedEmployeeId)
      localStorage.setItem('selectedEmployeeId', JSON.stringify(this.selectedEmployeeId))
    },

    // 异动新增-显示弹窗
    handleChangeAddDifferent (action, e) {
      console.log(action)
      console.log(e)
      this.changeDifferentAction = action // 所触发的行为：新增or减少
      this.changeDifferentTitleId = e // 点击的下拉选项的字段value
      this.$refs.ChangeDifferentModal.differentTime = '1'
      this.arrListDown.securitytype.map(item => {
        if (+e === +item.value) {
          this.changeDifferentTitleStr = item.label
        }
      })
      this.$refs.ChangeDifferentModal.show()
      // this.$refs.ChangeDifferentModal.differentTime = null
      this.$refs.ChangeDifferentModal.selectedEmployeeArr = this.selectedEmployeeArr // 选中的员工
    },

    // 异动减少-显示弹窗
    handleChangeAddDifferent2 (action, e) {
      console.log(action)
      console.log(e)
      this.changeDifferentAction = action // 所触发的行为：新增or减少
      this.changeDifferentTitleId = e // 点击的下拉选项的字段value
      this.$refs.ChangeDifferentModalNew.differentTime = '1'
      this.arrListDown.securitytype.map(item => {
        if (+e === +item.value) {
          this.changeDifferentTitleStr = item.label
        }
      })
      this.$refs.ChangeDifferentModalNew.show()
      // this.$refs.ChangeDifferentModalNew.differentTime = null
      this.$refs.ChangeDifferentModalNew.selectedEmployeeArr = this.selectedEmployeeArr // 选中的员工
    },

    // 批量导入-显示弹窗
    handleShowBatchImportModal () {
      // let clientLoginInfo = JSON.parse(localStorage.getItem('clientLoginInfo'))
      this.$refs.BatchImportModal.show()
      this.$refs.BatchImportModal.file = null
      this.$refs.BatchImportModal.errorData.isError = false
    },

    // 批量导入基数-显示弹窗
    handleShowBatchImportBaseDataModal () {
      // let clientLoginInfo = JSON.parse(localStorage.getItem('clientLoginInfo'))
      this.$refs.BatchImportBaseDataModal.file = null
      this.$refs.BatchImportBaseDataModal.errorData.isError = false
      this.$refs.BatchImportBaseDataModal.show()
    },

    // 批量导入合同-显示弹窗
    handleShowBatchImportContractModal () {
      this.$refs.BatchImportContractModal.file = null
      this.$refs.BatchImportContractModal.errorData.isError = false
      this.$refs.BatchImportContractModal.show()
    },

    // 批量上传照片附件-显示弹窗
    handleShowBatchUploadImgModal () {
      this.$refs.BatchUploadImgModal.file = null
      this.$refs.BatchUploadImgModal.show()
    },

    // 批量修改-显示弹窗
    handleShowBatchModifyModal () {
      // let clientLoginInfo = JSON.parse(localStorage.getItem('clientLoginInfo'))
      this.$refs.BatchModifyModal.show()
      this.$refs.BatchModifyModal.file = null
      this.$refs.BatchModifyModal.errorData.isError = false
    },

    // 商保替换前验证
    async checkCommercialChange () {
      let res = await EmployeesApi.checkCommercialChange(this.selectedEmployeeId)
      if (res.status === 200 && res.data.success) {
        this.handleShowShangbaoReplaceModal(res.data.data)
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 商保替换-显示弹窗
    handleShowShangbaoReplaceModal (data) {
      this.$refs.ShangbaoReplaceModal.show()
      // this.$refs.ShangbaoReplaceModal.isShowShangbaoReplaceModal = true
      // this.$refs.ShangbaoReplaceModal.transferData = [] // 在保人员
      // this.$refs.ShangbaoReplaceModal.targetKeys = [] // 被替换人员
      // this.$refs.ShangbaoReplaceModal.differentSecurity = '' // 默认单选项赋为空
      this.$refs.ShangbaoReplaceModal.selectArr = this.selectedEmployeeArr // 把勾选项赋到弹窗selectArr里面进行显示
      this.$refs.ShangbaoReplaceModal.commercialArr = data
      console.log('可替换的商保种类有：', data)
    },

    // 附件上传-显示弹窗
    handleShowUploadAccessoryModal (id) {
      this.$refs.UploadAccessoryModal.handleShowUploadAccessoryModal(id)
    },

    // 公积金在职调基-显示弹窗
    handleShowGongjijinZZtiaojiModal () {
      this.$refs.GongjijinZZtiaojiModal.isShowGongjijinZZtiaojiModal = true
      this.$refs.ShangbaoReplaceModal.selectArr = this.selectedEmployeeId // 把勾选项赋到弹窗selectArr里面进行显示
    },

    // 公积金补缴调基前验证是否属于同一公司
    async tiaojiCheckEmployee () {
      var params = {
        EmployeeIdList: this.selectedEmployeeId
      }
      let res = await SysWelfarePercentEmployeeAdjustConfigApi.checkEmployee(params)
      if (res.status === 200 && res.data.success) {
        // var tempQuery = {
        //   companyId: this.$route.query.companyId,
        //   companyName: this.$route.query.companyName,
        //   checkEmployeeNum: '3'
        // }
        // this.$router.replace({
        //   path: '/EmployeeBook',
        //   name: 'EmployeeBook',
        //   query: tempQuery
        // })
        this.handleShowGongjijinBJtiaojiModal()
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 公积金补缴调基-显示弹窗
    handleShowGongjijinBJtiaojiModal () {
      Object.keys(this.$refs.GongjijinBJtiaojiModal.formGongjijinFilter).forEach(key => {
        this.$refs.GongjijinBJtiaojiModal.formGongjijinFilter[key] = ''
      })
      // this.$refs.GongjijinBJtiaojiModal.isShowGongjijinBJtiaojiModal = true
      this.$refs.GongjijinBJtiaojiModal.show()
      this.$refs.GongjijinBJtiaojiModal.canEditor = true // 公积金补缴始终处于可编辑状态
      this.$refs.GongjijinBJtiaojiModal.selectArr = this.selectedEmployeeId // 把勾选项赋到弹窗selectArr里面进行显示
      console.log('this.$refs.GongjijinBJtiaojiModal.selectArr: ', this.$refs.GongjijinBJtiaojiModal.selectArr)
      this.$refs.GongjijinBJtiaojiModal.getTiaojiConfig(this.$route.query.companyId, this.selectedEmployeeId.join(','))
    },

    // // 删除员工-显示弹窗
    // handleSureDelete (id) {
    //   this.$refs.DeleteEmployeeModal.isShowDeleteEmployeeModal = true
    //   this.$refs.DeleteEmployeeModal.selectDelId = id
    //   console.log('显示删除员工弹窗时，当前选中的员工-ID是： ' + id)
    //   // console.log('selectDelId: ', this.$refs.DeleteEmployeeModal.selectDelId)
    // },
    // 是否删除前询问
    isDeleteModal (row) {
      this.$Modal.confirm({
        title: '是否确认删除该员工',
        onOk: () => {
          this.handleSureDelete(row)
        }
      })
    },

    // 删除员工-确认删除
    async handleSureDelete (id) {
      console.log('确认删除', id)
      let res = await EmployeesApi.deleteEmployee({ id: id })
      console.log('res: ', res)
      if (res.data.code === 200 && res.data.success) {
        this.$Message.success(res.data.message)
        this.query()
      } else {
        
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 批量操作-离职
    async employeeDimission () {
      console.log('this.selectedEmployeeId: ', this.selectedEmployeeId)
      let res = await EmployeesApi.employeeDimission(this.selectedEmployeeId)
      console.log('res: ', res)
      if (res.status === 200 && res.data.success) {
        this.$Message.success(res.data.message)
      } else {
        
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
      this.query()
    },

    // 批量上传照片附件成功(当前页面fn)
    handleUploadPhotoSuccess (res) {
      console.log('批量上传照片附件成功 res: ', res)
      if (res.code === 200 && res.success) {
        this.$Message.success(res.message)
      } else {
        this.$Message.error({
          content: res.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 导出员工数据
    async exportEmployees () {
      console.log('formInvoice: ', this.formInvoice)
      var params = {
        CompanyID: this.companyId,
        guids: this.selectedEmployeeId
      }
      let res = await EmployeesApi.exportEmployees({ ...params, ...this.formInvoice })
      console.log('res: ', res)
      if (res.status === 200 && res.data.success) {
        console.log('❤ 返回链接: ', baseUrl + res.data.message)
        window.open(baseUrl + res.data.message, '_blank')
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 批量导入-上传前文件
    handleBeforeUploadBatchImport (file) {
      this.batchImportFile = file
      console.log('file: ', this.batchImportFile)
    },

    // 批量导入成功(当前页面fn)
    uploadSuccessBatchImport (res) {
      console.log('批量导入res: ', res)
      if (res.code === 200 && res.success) {
        if (res.data) {
          if (res.data) {
            this.$refs.ErrorTemplateModal.downloadUrl = res.data
            this.$refs.ErrorTemplateModal.isShowErrorTemplateModal = true
          } else {
            this.$Message.success(res.message)
            this.query()
          }
        } else {
          this.$Message.success(res.message)
          this.query()
        }
      } else {
        this.$Message.error({
          content: res.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 批量修改-上传前文件
    handleBeforeUploadBatchModify (file) {
      this.batchModifyFile = file
      console.log('file: ', this.batchModifyFile)
    },

    // 批量修改成功(当前页面fn)
    uploadSuccessBatchModify (res) {
      console.log('批量修改res: ', res)
      if (res.code === 200 && res.success) {
        this.$Message.success(res.message)
        this.query()
      } else {
        this.$Message.error({
          content: res.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 确定下载错误模板
    handleSureErrorTemplate () {},

    handleMaxSizeTen () {
      this.$Message.error({
        content: '您上传的文件太大，上传文件大小不能超过10M',
        duration: 10,
        closable: true
      })
    },

    handleMaxSizeTifty () {
      this.$Message.error({
        content: '您上传的文件太大，上传文件大小不能超过50M',
        duration: 10,
        closable: true
      })
    },

    // 员工调动校验
    async checkEmployeeTransfer () {
      let res = await EmployeesApi.checkEmployeeTransfer(this.selectedEmployeeId)
      if (res.status === 200 && res.data.success) {
        this.handleShowMobilizeModal()
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },
    // 调动-显示弹窗
    handleShowMobilizeModal () {
      this.$refs.MobilizeModal.isShowMobilizeModal = true
      this.$refs.MobilizeModal.selectedCompanyId = ''
      this.$refs.MobilizeModal.companyListDown = []
      this.$refs.MobilizeModal.selectedEmployeeArr = this.selectedEmployeeArr // 选中的员工
      console.log('调动：', this.selectedEmployeeArr)
      this.$refs.MobilizeModal.getEmployeeTransferAllCompanys()
    }
  },

  // 实例销毁之前调用
  beforeDestroy () {
    this.getEnum = null
    this.query = null
  },

  beforeRouteLeave (to, from, next) {
    if (to.name == 'EmployeeCreate') {
      from.meta.keepAlive = true
      from.meta.notCache = false
    } else {
      // from.meta.keepAlive = false
      // from.meta.notCache = true
    }
    next()
  }
}
</script>

<style lang="less" scope>
  .d-f-c{
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
</style>
